@extends('layouts.admin.application')

@section('css')
    <link rel="stylesheet" href="/ace/assets/css/daterangepicker.css">
@endsection

@section('content')
    <div class="main-content">
        <div class="col-xs-12">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                    <li>会员管理</li>
                </ul>
            </div>
            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">

                        @include('layouts.partials._flash')

                        <div class="col-sm-2">
                            <div id="sample-table-2_length" class="dataTables_length">
                                <a href="{{ route('cashier.member.create') }}" class="btn btn-sm btn-primary">新增</a>
                                <a href="javascript:void(0);" class="btn btn-sm btn-purple del_all">删除</a>
                            </div>
                        </div>

                        <form>
                            <div class="col-sm-10">
                                <div class="dataTables_filter" id="sample-table-2_filter">
                                    <label>
                                        名称:<input type="text" name="keyword" aria-controls="sample-table-2"
                                                  placeholder="按姓名" value="{{Request::input('keyword')}}">
                                    </label>
                                    <label>
                                        电话:<input type="text" name="key" aria-controls="sample-table-2"
                                                  placeholder="按电话" value="{{Request::input('key')}}">
                                    </label>
                                    <label>
                                        <select class="dataTables_filter" name="store_id" style="width: 180px;">
                                            <option value="-1">所有门店</option>
                                            @foreach ($stores as $store)
                                                <option value="{{ $store->id }}"
                                                        @if($store->id == Request::input('store_id')) selected @endif>
                                                    {{ $store->name }}
                                                </option>
                                            @endforeach
                                        </select>
                                    </label>

                                    <label>日期统计: <input type="text" name="created_at" id="created_at"
                                                        aria-controls="sample-table-2" style="width: 174px;"
                                                        placeholder="选择时间日期" value="{{ Request::input('created_at') }}">
                                    </label>
                                    <label>
                                        <button type="submit" class="btn btn-xs btn-info" id="search">确定</button>
                                        <a href="{{ route('cashier.member.index') }}"
                                           class="btn btn-xs btn-default">重置</a>
                                    </label>
                                </div>
                            </div>
                        </form>

                    </div>
                    <table id="sample-table-2"
                           class="table table-striped table-bordered table-hover dataTable del-table"
                           aria-describedby="sample-table-2_info">
                        <thead>
                        <tr role="row">
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace" id="check_all">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>联系方式</th>
                            <th>生日</th>
                            <th>积分</th>
                            <th>消费次数</th>
                            <th>消费总额</th>
                            <th>经办人</th>
                            <th>创建日期</th>
                            <th>所属门店</th>
                            <th>消费记录</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        @foreach($members as $member)
                            <tr class="odd" data-id="{{$member->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace checked_id" name="checked_id[]"
                                               value="{{$member->id}}">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{$member->id}}</td>
                                <td>{{$member->name}}</td>
                                <td>
                                    @if($member->sex == 1)
                                        <span class="label label-purple arrowed-in-right arrowed">男</span>
                                    @else
                                        <span class="label label-pink arrowed-in-right arrowed">女</span>
                                    @endif
                                </td>
                                <td>{{$member->phone}}</td>
                                <td>{{$member->birthday}}</td>
                                <td style="color: red">{{$member->score}} 分</td>
                                <td style="color: #0088cc">{{$member->buy_count}} 次</td>
                                <td style="color: green">{{$member->amount}} 元</td>
                                <td>{{$member->manager}}</td>
                                <td>{{$member->created_at}}</td>
                                <td>{{$member->store['name']}}</td>
                                <td>
                                    <a href="/admin/cashier/sale/member_sale?member_id={{ $member->id }}">
                                        <span class="label label-yellow arrowed-in-right arrowed">查看历史</span>
                                    </a>
                                </td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="green" href="{{ route('cashier.member.edit', $member->id) }}"><i
                                                    class="icon-pencil bigger-130"></i></a>
                                        <a class="red del_one" href="javascript:;">
                                            <i class="icon-trash bigger-130"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <div class="row">
                        <div class="col-sm-6">共 {{$members->total()}} 条记录</div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_bootstrap">
                                <ul class="pagination">
                                    {{ $members->appends(Request::all())->links() }}
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script src="/ace/assets/js/date-time/daterangepicker.min.js"></script>
    <script src="/ace/assets/js/date-time/moment.min.js"></script>
    <script>
        $(function () {
            //时间插件
            $('#created_at').daterangepicker({
                "locale": {
                    "applyLabel": "确定",
                    "cancelLabel": "取消"
                }
            });

            //全选，反选
            $("#check_all").click(function () {
                $(':checkbox').prop("checked", this.checked);
            });

            //多选删除
            $('.del_all').click(function () {
                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

                if (confirm('确定要删除么？')) {
                    var checked_id = $(".checked_id:checked").serialize();

                    $.ajax({
                        type: "DELETE",
                        url: "{{route('cashier.member.destroy_more')}}",
                        data: checked_id,
                        success: function () {
                            location.href = location.href;
                        }
                    });

                }
            });

            //删除单条
            $('.del_one').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);

                $.ajax({
                    type: 'DELETE',
                    url: '/admin/cashier/member/' + id,
                    data: id,
                    success: function () {
                        _this.parents('tr').fadeOut(400);
                    }
                })
            });


        })
    </script>
@endsection